import { MiddlewareConsumer, Module, NestModule, RequestMethod } from '@nestjs/common';
import { FrontService } from '../service/front.service';
import { FrontController } from './controller/front.controller';
import { JwtModule } from '@nestjs/jwt';
import { FrontAuthService } from '../service/front-auth.service';
import { VerifyMiddleware } from '../middleware/verify/verify.middleware';
import { WordService } from '../service/word.service';
import { TypeOrmModule } from '@nestjs/typeorm';
@Module({
  imports:[
    JwtModule.register({
      secret: process.env.JWT_SECRET || 'your-secret-key', // 从环境变量读取密钥
      signOptions: { expiresIn: '30d' }, // 过期时间设置为 30 天
    }),
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: '192.168.157.128', // MySQL服务器地址
      port: 3306, // MySQL服务器端口
      username: 'root', // MySQL用户名
      password: 'liyatai0119', // MySQL密码
      database: 'dali', // 数据库名
      entities: [__dirname + '/../**/*.entity{.ts,.js}'], // 实体文件路径
      synchronize: false, // 根据实体自动创建数据库表，生产环境建议设置为false
      logging: true, // 启用日志
    }),
  ],
  providers: [FrontService,FrontAuthService,WordService],
  controllers: [FrontController]
})
export class FrontModule implements NestModule{
  configure(consumer: MiddlewareConsumer) {
      consumer
        .apply(VerifyMiddleware)
        .exclude({path:'front/login',method:RequestMethod.ALL})
        .forRoutes(FrontController)
  
    }
}
